package com.cqw.jackson;

import com.cqw.utils.AESUtil;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.KeyDeserializer;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-08-25 17:43
 * @Description:
 */
@Component
public class IdKeyDeserializer extends KeyDeserializer {



    /**
     * Method called to deserialize a {@link Map} key from JSON property name.
     *
     * @param key
     * @param ctxt
     */
    @Override
    public Object deserializeKey(String key, DeserializationContext ctxt) throws IOException {
        if (StringUtils.isBlank(key)) {
            return null;
        }
        return StringUtils.isBlank(AESUtil.decrypt(key, "q1")) ? null : Long.valueOf(AESUtil.decrypt(key, "q1"));
    }
}
